/******************* 公共变量 *******************/
var type = core.getUrlData('type'),
	shareId = core.getUrlData(['tui_id', 'a_id']);

/******************* Vue初始化代码 *******************/
var vm = new Vue({
	el: '.wrap',
	data: {
		phone: '',
		// password: '',
		code: '',
		type: type,
		btnJudge: true,
		tui_id: shareId[0],
		a_id: shareId[1],
		sex: '',
		age: '',
		star: '',
		wxLogin: (shareId[0] ? (wxLoginUrl + '?tui_id=' + shareId[0] + '&a_id=' + shareId[1]) : wxLoginUrl)
	},
	methods: {
		checkPhone: function () {
			!core.phoneJudge(this.phone) && core.layerHint('请输入正确手机号');
		},
		// checkPassword: function () {
		// 	!core.pwJudge(this.password) && core.layerHint('请输入6-16位，字母或数字密码');
		// },
		checkCode: function () {
			!core.securityCodeJudge(this.code) && core.layerHint('请输入6位数字验证码');
		},
		selectSex: function (index) {
			$('html body .wrap .user-forget .sex div span').eq(index).addClass('active').siblings().removeClass('active');
			this.sex = $('html body .wrap .user-forget .sex div span').eq(index).attr('sex');
		},
		submit: function () {
			var _this = this;
			function updateData() {
				$.ajax({
					url: ((type == 'register') || (type == 'complete')) ? registerUrl : forgetUrl,
					type: 'post',
					data: {
						mobile: _this.phone,
						// password: _this.password,
						sms_code: _this.code,
						tui_id: _this.tui_id,
						a_id: _this.a_id,
						sex: _this.sex,
						age: _this.age,
						star: _this.star,
						isweb: ((type == 'register') ? '101' : '')
					},
					success: function (data) {
						console.log(data)
						
						setTimeout(function () {
							_this.btnJudge = true;
						}, 1000);
						if (data.status == 1) {
							core.hintHref(data.info, (((type == 'register') || (type == 'complete')) ? ((_this.a_id ? (identifyUrl + '?user_id=' + data.user_id + '&tui_id=' + _this.tui_id + '&a_id=' + _this.a_id) : (identifyUrl + '?user_id=' + data.user_id))) : loginUrl));
						} else {
							core.layerHint(data.info);
						}
					}
				});
			}
			if (core.phoneJudge(this.phone)) {
				// if (core.pwJudge(this.password)) {
					if (core.securityCodeJudge(this.code)) {
						if ((type == 'register') || (type == 'complete')) {
							if (this.age && this.star) {
								if (this.sex) {
									if (this.btnJudge) {
										this.btnJudge = false;
										if (type == 'complete') {
											common.layerConfirm({
												content: '性别一旦提交将无法修改，提交错误信息将被平台驳回',
												btn: ['确定', '取消'],
												bacClose: false,
												yesClose: false,
												yes: function () {
													updateData();
												}
											});
										} else {
											updateData();
										}
									}
								} else {
									core.layerHint('请选择性别');
								}
							} else {
								core.layerHint('请选择生日');
							}
						} else {
							if (this.btnJudge) {
								this.btnJudge = false;
								updateData();
							}
						}
					} else {
						core.layerHint('请输入6位数字验证码');
					}
				// } else {
					// core.layerHint('请输入6-16位，字母或数字密码');
				// }
			} else {
				core.layerHint('请输入正确手机号');
			}
		}
	},
	computed: {
		
	},
	components: {
		
	},
	created: function () {
		
	},
	mounted: function () {
		var _this = this;
		common.bindBack();

		$('title').html((type == 'register') ? '注册' : ((type == 'complete') ? '绑定手机' : '忘记密码'));
		/******************* 获取验证码倒计时功能 *******************/
		var count = core.countDownTime({
			btn: 'html body .wrap .user-forget .set-pw div:nth-child(2) em',
			event: 'tap',
			// show: 'body .wrap .store-app .store-app-box .store-app-con form section span',
			textEnd: '发送',		// 倒计时结束时显示的文字
			countTime: 60000,		// 设定倒计时时间
			startAjax: function () {
				if (core.phoneJudge(_this.phone)) {
					return true;
				} else {
					core.layerHint('请输入正确手机号');
					return false;
				}
			},
			ajaxJudge: {
				url: codeUrl,
				type: 'post',
				data: function () {
					return {
						mobile: _this.phone
					};
				},
				success: function (data, count) {
					console.log(data)
					core.layerHint(data.info);
					if (data.status == 1) {
						count();
					}
				}
			}
		});

				/******************* 日期选择窗 *******************/
		// 时间选择
		$dateTime = $('html body .wrap .user-forget .age input');

		// 关闭弹窗的功能
		$dateTime.datetimePicker({
			cssClass: 'date-time',
			toolbarTemplate: '<header class="bar bar-nav">请选择时间</header>\
			<footer class="picker-footer">\
				<span class="confirm">确定</span>\
			</footer>',
			maxDate: core.dateDetail().ymd2,
			onOpen: function () {
				var $selectCon = $('html body .date-time .picker-items .picker-center-highlight, .picker-item'),
						selectConHeight = core.decimalRound($selectCon.height(), 0) + 'px';
				$selectCon.css({
					height: selectConHeight,
					lineHeight: selectConHeight
				});
				common.pickerBacIn();
				$('html body .date-time .picker-items .picker-items-col:nth-child(4), html body .date-time .picker-items .picker-items-col:nth-child(5), html body .date-time .picker-items .picker-items-col:nth-child(6), html body .date-time .picker-items .picker-items-col:nth-child(7)').css(dn);
				_this.isDateTimeClose = false;
				$('html body .date-time .picker-footer span').on('tap', function () {
					_this.isDateTimeClose = true;
					$dateTime.picker('close');
				});
			},
			onClose: function (picker) {
				common.pickerBacOut();
				if (_this.isDateTimeClose) {
					var age = core.decimalRound((core.dateDetail().getTime - (new Date(picker.value[0], picker.value[1], picker.value[2], picker.value[3], picker.value[4]))) / 1000 / 60 / 60 / 24 / 365, 0);

					if (age >= 18) {
						_this.age = age;
						_this.star = core.constellation(picker.value[1], picker.value[2]);
					} else {
						core.layerHint('年龄不可小于18岁哦');
					}
				}
			}
		});
	},
	updated: function () {
		
	}
});